<template>
    <div class="w100p fullbg">
        <div class="_container_ clearfix pt46 postionre">
            <!--导航-->
            <ChildrenRouter :routers="navs"
                            class="fl"
                            :two_id="two_id"
                            @handleClose="handleClose"
                            @handleOpen="handleOpen"
                            :ref="'childrenRouters'"
            ></ChildrenRouter>
            <!--内容-->
            <div class="w82_5p bgfff fr minh814 postionre pb120 media_w100p">
                <Title :links="links" @typeOneTap="typeOneTap" @menuShow="menuShow"></Title>
                <transition name="fade" mode="out-in">
                    <router-view :setting="setting" @tologin="tologin"/>
                </transition>

            </div>
        </div>
    </div>
</template>

<script>
    import ChildrenRouter from './../components/ChildrenRouter'
    import Title from './../components/commons/Title'
    export default {
        name: "Contact",
        components:{ChildrenRouter,Title},
        data(){
            return{
                navs:{
                    name:'联系我们',
                    data:[
                        {name : '联系我们', link:'/contact/msg',term_id:'/contact/msg'},
                        {name : '意见留言', link:'/contact/idea',term_id:'/contact/idea'},
                        {name : '联系客服', link:'/contact/service',term_id:'/contact/service'},
                    ]
                },
                links:{
                    title:'',
                    one:{text:'联系我们',link:'/contact/msg'},
                    two:{text:'联系我们',link:''},
                    four:'',
                    index:0,
                    contact:true
                },
                two_id:'/contact/msg',
                active_router:'/contact/msg',
                setting:'',
                script_tool:null,
                script_geo:null
            }
        },
        created(){
            var v = this , _path = '' , _link = this.navs.data;
            v.script_tool = document.createElement('script');
            v.script_geo = document.createElement('script');
            v.script_tool.src = 'https://cache.amap.com/lbs/static/addToolbar.js';
            v.script_geo.src = 'http://webapi.amap.com/maps?v=1.4.6&key=fc82fd3432125c4a9872bb6a1e85e527&plugin=AMap.Geocoder';
            document.body.appendChild(v.script_tool);
            document.body.appendChild(v.script_geo);
            _path = this.$route.path ;
            if(_path == _link[0].link){
                v.links.two.text = v.navs.data[0].name;
            }else if(_path == _link[1].link){
                v.links.two.text = v.navs.data[1].name;
            }else if(_path == _link[2].link){
                v.links.two.text = v.navs.data[2].name;
            }
            v.links.title = v.links.two.text;
            v.two_id = _path;
            this.getMsg();
        },
        beforeDestroy(){
            document.body.removeChild(this.script_tool);
            document.body.removeChild(this.script_geo);
        },
        methods:{
            getMsg(){
                var v = this;
                v.$axios.post('/index.php?g=portal&m=index&a=setting_all')
                    .then((res) => {
                        res = res.data;
                        if (res.result == 1) {
                            v.setting = res.setting;
                        } else {
                            v.$message.error('获取失败！');
                        }
                    }).catch((err) => {
                    v.$message.error('获取失败！');
                });
            },
            handleOpen(key,keypath){
                this.rooterChange(key);
            },
            handleClose(key,keypath){
                this.rooterChange(key);
                // console.log(key,keypath)
            },
            rooterChange(key){
                var _index = key.index;
                var _path = this.navs.data[_index].link;
                this.links.two.text = this.navs.data[_index].name;
                this.two_id = this.navs.data[_index].link;
                this.links.title =  this.links.two.text;
                this.$router.push(_path);
            },
            tologin(){
                this.$emit('tologin')
            },
            typeOneTap(){
                this.links.two.text = '联系我们';
                this.two_id = '/contact/msg';
                this.$router.push(this.two_id);
            },
            menuShow(){
                this.$refs.childrenRouters.menuShow()
            }
        }
    }
</script>

<style>

</style>































